package com.csb.service.impl;

import com.csb.config.MyConstants;
import com.csb.mapper.AssetMapper;
import com.csb.pojo.Apply;
import com.csb.pojo.AssetInfo;
import com.csb.pojo.AssetTypesRate;
import com.csb.service.AssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AssetServiceImpl implements AssetService {
    // 依赖
    @Autowired
    private AssetMapper assetMapper;

    /**
     * 获取本页的固定资产信息
     *
     * @param cond
     * @return
     */
    @Override
    public List<AssetInfo> getAssetInfoWithPage(Map<String, Object> cond) {
        return assetMapper.getAssetInfoWithPage(cond);
    }

    /**
     * 获取本次查询的总资产数
     *
     * @param cond
     * @return
     */
    @Override
    public int getAssetCount(Map<String, Object> cond) {
        return assetMapper.getAssetCount(cond);
    }

    /**
     * 添加信息前名称的验证
     *
     * @param asId
     * @return
     */
    @Override
    public boolean ifExistsAsId(String asId) {
        return assetMapper.ifExistsAsId(asId) > 0;
    }

    /**
     * 添加资产信息
     *
     * @param assetInfo
     * @return
     */
    @Override
    public boolean saveAssetInfo(AssetInfo assetInfo) {
        return assetMapper.saveAssetInfo(assetInfo) > 0;
    }

    /**
     * 根据资产内部编号,将资产信息设置为故障
     *
     * @param assetInfo
     * @return
     */
    @Override
    public boolean delAssetInfo(AssetInfo assetInfo) {
        return assetMapper.delAssetInfo(assetInfo) > 0;
    }

    /**
     * 根据资产内部编号,修改资产信息
     *
     * @param assetInfo
     * @return
     */
    @Override
    public boolean modifyAssetInfo(AssetInfo assetInfo) {
        return assetMapper.modifyAssetInfo(assetInfo) > 0;
    }

    /**
     * 根据资产内部编号,将资产信息批量设置为故障
     *
     * @param ids
     * @param assetInfo
     * @return
     */
    @Override
    public boolean batchDelAssetInfo(String[] ids, AssetInfo assetInfo) {
        return assetMapper.batchDelAssetInfo(ids, assetInfo) > 0;
    }

    /**
     * 将资产折旧
     * @param assetAsstateWorthless
     * @return
     */
    @Override
    public boolean depreciation(int assetAsstateWorthless) {
        return assetMapper.depreciation(assetAsstateWorthless) > 0;
    }

    /**
     * 获取不可用资产一览
     * @param assetAsstateWorthless
     * @param assetIsBreakYes
     * @return
     */
    @Override
    @Cacheable(value = "worthless", key = "'getWorthLessAssetList'")
    public List<Apply> getWorthLessAssetList(int assetAsstateWorthless, int assetIsBreakYes) {
        return assetMapper.getWorthLessAssetList(assetAsstateWorthless,assetIsBreakYes);
    }

    /**
     * 获取资产占比
     * @return
     */
    @Override
    @Cacheable(value = "assetTypesRate", key = "'getAssetTypesRate'")
    public List<AssetTypesRate> getAssetTypesRate() {
        return assetMapper.getAssetTypesRate();
    }
    /**
     * 维修资产
     * @return
     */
    @Override
    public boolean maintainAssetInfo(AssetInfo assetInfo) {
        // 设置故障状态
        assetInfo.setIsBreak(MyConstants.ASSET_IS_BREAK_NO);
        // 设置资产状态
        assetInfo.setAsState(MyConstants.ASSET_ASSTATE_NOUSE);
        // 返回
        return assetMapper.maintainAssetInfo(assetInfo);
    }

    @Override
    // @Cacheable(value = "getAssetInfoByAccount")
    public List<AssetInfo> getAssetInfo(String account) {
        return assetMapper.getAssetInfo(account);
    }
}
